package com.usaas.search.controller.admin;

import com.usaas.common.annotation.Log;
import com.usaas.common.core.controller.BaseController;
import com.usaas.common.core.domain.AjaxResult;
import com.usaas.common.enums.BusinessType;
import com.usaas.common.utils.poi.ExcelUtil;
import com.usaas.search.dto.PlatWelfareMessageDto;
import com.usaas.search.service.IPlatWelfareMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 福利通知Controller
 *
 * @author Helios
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/admin/search/platWelfareMessage")
public class AdminPlatWelfareMessageController extends BaseController {

    @Autowired
    private IPlatWelfareMessageService platWelfareMessageService;

    /**
     * 查询福利通知列表
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:list')")
    @Log(title = "管理端福利通知list查询", businessType = BusinessType.OTHER)
    @PostMapping("/list")
    public AjaxResult list(@RequestBody PlatWelfareMessageDto platWelfareMessageDto) {
        List<PlatWelfareMessageDto> list = platWelfareMessageService.queryList(platWelfareMessageDto);
        return AjaxResult.success(list);
    }


    /**
     * 查询福利通知分页列表
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:list')")
    @Log(title = "管理端福利通知page查询", businessType = BusinessType.OTHER)
    @PostMapping("/page")
    public AjaxResult page(@RequestBody PlatWelfareMessageDto platWelfareMessageDto) {
        return platWelfareMessageService.queryPage(platWelfareMessageDto);
    }


    /**
     * 导出福利通知列表
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:export')")
    @Log(title = "管理端导出福利通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlatWelfareMessageDto platWelfareMessageDto) {
        List<PlatWelfareMessageDto> list = platWelfareMessageService.queryList(platWelfareMessageDto);
        ExcelUtil<PlatWelfareMessageDto> util = new ExcelUtil<>(PlatWelfareMessageDto.class);
        util.exportExcel(response, list, "福利通知数据");
    }

    /**
     * 获取福利通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:query')")
    @Log(title = "管理端获取福利通知详情查询", businessType = BusinessType.OTHER)
    @PostMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestBody PlatWelfareMessageDto platWelfareMessageDto) {
        return AjaxResult.success(platWelfareMessageService.queryById(platWelfareMessageDto.getId()));
    }

    /**
     * 新增福利通知
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:add')")
    @Log(title = "管理端新增福利通知", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody PlatWelfareMessageDto platWelfareMessageDto) {
        return toAjax(platWelfareMessageService.add(platWelfareMessageDto));
    }

    /**
     * 修改福利通知
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:edit')")
    @Log(title = "管理端修改福利通知", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public AjaxResult edit(@RequestBody PlatWelfareMessageDto platWelfareMessageDto) {
        return toAjax(platWelfareMessageService.update(platWelfareMessageDto));
    }

    /**
     * 删除福利通知
     */
    @PreAuthorize("@ss.hasPermi('search:platWelfareMessage:remove')")
    @Log(title = "管理端删除福利通知", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult del(@RequestBody PlatWelfareMessageDto platWelfareMessageDto) {
        return toAjax(platWelfareMessageService.removeBatch(platWelfareMessageDto.getIds()));
    }

}
